﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Net;

namespace Pipes.Ui
{
  static class Program
  {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
    }

    public static void Test()
    {
      foreach (var fmt in Clipboard.GetDataObject().GetFormats())
      {
        Debug.Print(fmt);
      }
    }
    public static void GetFiles()
    {
      if (Clipboard.ContainsFileDropList())
      {
        foreach (var file in Clipboard.GetFileDropList())
        {
          Debug.Print("{0}|{1}|{2}", file, Regex.Match(Path.GetFileName(file), @"^\w+").Value.Replace("_", "-"), new FileInfo(file).LastWriteTime);
        }
      }
    }

    public static void SqlToVisualBasic()
    {
      var reader = new IO.StringTextSource(Clipboard.GetText()).Pipe(new Data.DelimitedTextReader());
      reader.AddDelim('\r');
      var writer = new System.IO.StringWriter();
      var vb = new Code.VisualBasicCodeWriter(writer);
      foreach (var line in reader)
      {
        vb.Raw("sql.Line(").StringValue(line).Raw(")");
        vb.LineEnd();
      }
      vb.Flush();
      Debug.Print(writer.ToString());
    }
  }
}
